﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using Terralever.Facebook.UI.Design;
using System.Globalization;

namespace Terralever.Facebook.UI.FbmlControls
{
    /// <summary>
    /// Displays content inside the tag only if the logged-in user is permitted by the specified privacy setting of the specified user.
    /// </summary>
    /// <remarks>
    /// <para>The Facebook documentation for the rendered control can be found 
    /// <a href="http://wiki.developers.facebook.com/index.php/Fb:if-can-see-photo" target="_blank">here</a>.</para>
    /// </remarks>
    [ToolboxData("<{0}:IfCanSeePhoto runat=\"server\"></{0}:IfCanSeePhoto>")]
    [DefaultProperty("PhotoID")]
    public class IfCanSeePhoto : LogicTestControl
    {
        /// <summary>
        /// Gets or sets the ID of the photo to check.
        /// </summary>
        [Browsable(true)]
        [Category(FbmlConstants.FBML_REQD_ATTR)]
        [Description("Specifies the photo ID to check.")]
        [DefaultValue(0)]
        [FbmlRequired(IsRequired = true)]
        public long PhotoID
        {
            get;
            set;
        }

        /// <summary>
        /// Optionally gets or sets the ID of another user if the current user should be able to see the photo through another user.
        /// </summary>
        [Browsable(true)]
        [Category(FbmlConstants.FBML_OPT_ATTR)]
        [Description("Specifies the user ID to use instead of the currently logged in user.")]
        [DefaultValue(0)]
        public long UserID
        {
            get;
            set;
        }

        /// <inheritdoc />
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);

            if (PhotoID == 0)
                throw new RequiredFbmlAttributeNotSetException("PhotoID", PhotoID);
            writer.AddAttribute("pid", PhotoID.ToString(CultureInfo.InvariantCulture));

            if (UserID != 0)
                writer.AddAttribute("uid", UserID.ToString(CultureInfo.InvariantCulture));
        }

        /// <inheritdoc />
        protected internal override string ElementName
        {
            get { return FbmlConstants.FB_IF_CAN_SEE_PHOTO; }
        }
    }
}
